 <?php
session_start();

// Open database connection
$dbHost = "sid3.comp.nus.edu.sg";
$dbHostPort="1521";
$dbServiceName = "sid3.comp.nus.edu.sg";
$usr = "A0103863";
$pswd = "cs2102std";
$dbConnStr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$dbHost.")(PORT=".$dbHostPort."))(CONNECT_DATA=(SERVICE_NAME=".$dbServiceName.")))";
$dbConn = oci_connect($usr,$pswd,$dbConnStr);

if(!$dbConn)
{
        $err = oci_error();
        print('Could not establish a database connection: ' . $err['message']);
}
else
{
        // Insert a new message into the database
        $strSQL = "INSERT INTO message (subject, body, sender, receiver, message_time) VALUES ('".$_GET['subject']."','".$_GET['body']."','".$_SESSION['user']."','".$_GET['receiver']."',sysdate)";
        
        //echo $strSQL;
        $stmt = oci_parse($dbConn,$strSQL);
        if (!oci_execute($stmt)) {
                $err = oci_error($stmt);
                print('Query failed: '.$err['message']);
        }else{
                print "<h1>The message was successfully sent </h1>";
                print "<a href='index.php'>Go back to the home page</a>";
        }
        
}
?>
